<!--单选框-->
<template>
	<zh-form-item
		:ref="prop"
		:label="label"
		:prop="prop"
		:span="span"
		:md="md"
		:sm="sm"
		:xs="xs"
		:lg="lg"
		:xl="xl"
		:offset="offset"
		:push="push"
		:pull="pull"
		:tag="tag"
	>
    <el-checkbox-group v-if="!allAttrs.butttonFlag" v-bind="allAttrs" :disabled="getDisabled()" :size="mySize" v-model="value" :id="'zhCheckboxF' + columnId" :name="'zhCheckboxF' + columnId" @change="onChange">
			<el-checkbox :key="item[nodeValue]" :border="allAttrs.border" :trueLabel="allAttrs.trueLabel" :falseLabel="allAttrs.falseLabel"  :disabled="item['disabled']" v-for="item in theOptions" :label="item[nodeValue]">
				<slot>{{ item[showLabel] }}</slot>
			</el-checkbox>
		</el-checkbox-group>
		<el-checkbox-group v-else v-bind="allAttrs" :size="mySize" v-model="value" :id="'zhCheckboxF' + columnId" :name="'zhCheckboxF' + columnId" @change="onChange">
			<el-checkbox-button :key="item[nodeValue]" :trueLabel="allAttrs.trueLabel" :falseLabel="allAttrs.falseLabel"  :disabled="item['disabled']" v-for="item in theOptions" :label="item[nodeValue]">
				<slot>{{ item[showLabel] }}</slot>
			</el-checkbox-button>
		</el-checkbox-group>
	</zh-form-item>
</template>

<script lang="ts" setup>
import { formItemProps, selectProps, itemProps, itemController, initSelect } from '../lib/mapController';
// 定义属性
const props = defineProps({
	...formItemProps,
	...selectProps,
	...itemProps,
	modelValue: [String, Number, Boolean,Array],
});
const attrs = useAttrs();
const emit = defineEmits(['update:modelValue','change']);
const allAttrs = computed(() => {
	return Object.assign(props.extend, attrs);
});
const { value, globalSize } = itemController(props, allAttrs.value, emit);
const state = reactive({
	mySize: allAttrs.value.size,
});
const onChange=(value)=>{
  emit('change', value);
}
// 初始化
globalSize(state);
// 输出
const { theOptions, nodeValue, showLabel } = initSelect(props, value);
const { mySize } = toRefs(state);
let golbalProps: any = inject('golbalProps', {});
//获取可编辑设置
const getDisabled = () => {
	if (props.disabled === null || props.disabled === undefined) {
		return golbalProps.disabled;
	} else {
		return props.disabled;
	}
};
</script>
<script lang="ts">
// 声明额外的选项
export default {
	name: 'zh-form-radio',
	inheritallAttrs: false,
};
</script>
